package cate.game.play.skill.effect.base;


import cate.common.util.XT;
import cate.game.attr.FightAttr;
import cate.game.play.base.HpCfg;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.config.PlayCfgUtil;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.SkillActionCtx;
import easy.java.dev.note.NoteClass;

import java.util.ArrayList;
import java.util.List;

@NoteClass(value = "血量变更SE",detail = "伤害、治疗、复活等都继承他")
public abstract class HpSE extends SE {

    protected List<HpCfg> cfgs = new ArrayList<>();

    //总的技能系数
    protected double totalCoeff;

    @Override
    public void parse(String code) {
        for (PlayCfgArgs args : PlayCfgUtil.parseList(code)) {
            addHpCfg(new HpCfg(args));
            parseArgs(args);
        }
    }

    @Override
    public void parseExt(String code) {
        for (PlayCfgArgs args : PlayCfgUtil.parseList(code)) {
            addHpCfg(new HpCfg(args));
        }
    }

    private void addHpCfg(HpCfg cfg) {
        cfgs.add(cfg);
    }

    protected void parseArgs(PlayCfgArgs args){

    }


    /**
     * 计算血量变化的初始值
     * @param casterAttr
     * @param targetAttr
     * @return
     */
    protected double calcHpChange(SkillActionCtx action, Fighter target, FightAttr casterAttr, FightAttr targetAttr) {
        double v = 0;
        totalCoeff = 0d;
        List<HpCfg> settles = new ArrayList<>();
        XT.merge(settles, cfgs);
        XT.merge(settles, parent.getHpCfgs(target.getPid()));
        XT.merge(settles, action.getSkill().param.getHpCfgs());
        XT.merge(settles, action.getMove().param.getHpCfgs());
        for (HpCfg cfg : settles) {
            v += cfg.settle(action.getActor(), target, casterAttr, targetAttr);
            totalCoeff+=cfg.totalCeoff();
        }
        return v;
    }

    /**
     * 仙术技能目标系数
     * @param targetNum
     * @return
     */
    protected double xsTargetCoeff(int targetNum){
        switch (targetNum){
            case 1:return 1d;
            case 2:return 0.6d;
            case 3:return 0.48d;
            case 4:return 0.4d;
            case 5:return 0.36d;
            case 6:
            default:return 0.34d;
        }
    }
}
